package com.interrupt;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Executor {


    /**
     * 调用Executor的shutdown()方法会等待线程都执行完毕之后在关闭，但如果调用是shutdownNow()方法，则相当于调用每个线程的interrupt()方法。
     * @param args
     */
    public static void main(String[] args) {
        ExecutorService executorService= Executors.newCachedThreadPool();
        executorService.execute(()->{
            try {
                Thread.sleep(2000);
                System.out.println("Thread run");
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        });
        executorService.shutdownNow();
        System.out.println("Main run");
    }

}
